#ifndef TINX_BUFFER_H
#define TINX_BUFFER_H

#include <tinx/lock.h>
#include <tinx/list.h>
#include <tinx/types.h>

#define HASH_COUNT    31
#define BUFFER_COUNT  128

typedef struct bdesc_t
{
    u32 count; // buffer 数量
    size_t size;
    lock_t lock;
    list_t table[HASH_COUNT];
    list_t free_list;
    list_t idle_list;
    list_t waiters;
} bdesc_t;

typedef struct buffer_t
{
    lock_t lock;
    bdesc_t *desc;
    void *data;
    idx_t block;
    dev_t dev;
    list_node_t rnode;
    list_node_t hnode;
    bool dirty;
    bool vaild;
    int count; // 引用次数
} buffer_t;

buffer_t *getblk(dev_t dev, idx_t block, size_t size);
buffer_t *bread(dev_t dev, idx_t block, size_t size);
int bwrite(buffer_t *buf);
int brelse(buffer_t *buf);

#endif